package com.nineclock.system.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@Slf4j
public class MemberParseListener extends AnalysisEventListener<ExcelMember> {

    private SysCompanyUserService companyUserService;

    public MemberParseListener(SysCompanyUserService companyUserService){
        this.companyUserService = companyUserService;
    }

    private List<ExcelMember> list = new ArrayList<>();

    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        log.info(data.toString());
        list.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info(list.toString());
        companyUserService.saveData(list);
    }
}
